//------------------------------------------------------
//ContactManagerPanel.java
//------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class ContactManagerPanel extends JPanel {
	
	private JButton AddButton, modifyButton, deleteButton, pwbtn, Search_btn, savebtn, M_button;
	private JLabel Firstn_lbl, Lastn_lbl, pos_lbl, depart_lbl, coname_lbl, address_lbl, telnum_lbl, faxnum_lbl, monum_lbl, email_lbl, homp_lbl, 
	               View_lbl, password, Search_lbl, pwlbl, search_lbl2, M_Firstn_lbl, M_Lastn_lbl, M_pos_lbl, M_depart_lbl, M_coname_lbl,  
	               M_address_lbl, M_telnum_lbl, M_faxnum_lbl, M_monum_lbl, M_email_lbl, M_homp_lbl, M_main_lbl;
	private JTextField Firstn_txt, Lastn_txt, pos_txt, depart_txt, coname_txt, address_txt, telnum_txt, faxnum_txt, mobnum_txt, email_txt, 
	                   homp_txt, Search_txt, passwordField, M_Firstn_txt, M_Lastn_txt, M_pos_txt, M_depart_txt, M_coname_txt, M_address_txt, 
	                   M_telnum_txt, M_faxnum_txt, M_mobnum_txt, M_email_txt, M_homp_txt;
	private JTabbedPane tab;
	private JPanel ViewPanel, DisplayPanel, AddPanel, SearchPanel, PasswordPanel, ModifyPanel;
	private JTextArea ViewTArea;
	private JList ContactList, SearchList;
	DefaultListModel model, model2;
	private JFrame modiframe;
	ContactCollection contact = new ContactCollection();

	public ContactManagerPanel() {
							
		setBackground(new Color(204, 255, 255));
		setLayout(null);
		setPreferredSize(new Dimension(800, 500));
		
		ButtonListener listener = new ButtonListener();

		ViewPanel = new JPanel();
		ViewPanel.setBackground(new Color(204, 255, 255));
		ViewPanel.setBounds(453, 20, 347, 477);
		add(ViewPanel);
		ViewPanel.setLayout(null);

		View_lbl = new JLabel("View");
		View_lbl.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		View_lbl.setBounds(12, 22, 52, 28);
		ViewPanel.add(View_lbl);

		ViewTArea = new JTextArea();
		ViewTArea.setForeground(new Color(51, 51, 51));
		ViewTArea.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		ViewTArea.setBounds(12, 66, 323, 377);
		ViewPanel.add(ViewTArea);

		modifyButton = new JButton("수정");
		modifyButton.setBackground(Color.WHITE);
		modifyButton.setFont(new Font("맑은 고딕", Font.PLAIN, 13));

		modifyButton.setBounds(179, 449, 72, 23);
		ViewPanel.add(modifyButton);

		deleteButton = new JButton("삭제");
		deleteButton.setBackground(Color.WHITE);
		deleteButton.setFont(new Font("맑은 고딕", Font.PLAIN, 13));

		modifyButton.addActionListener(listener);

		deleteButton.setBounds(263, 449, 72, 23);
		ViewPanel.add(deleteButton);

		savebtn = new JButton("저장");
		savebtn.setBackground(Color.WHITE);
		savebtn.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		savebtn.setBounds(263, 4, 72, 23);
		ViewPanel.add(savebtn);
		savebtn.addActionListener(listener);

		deleteButton.addActionListener(listener);

		//tab
		
		tab = new JTabbedPane(JTabbedPane.LEFT);
		tab.setForeground(new Color(0, 0, 51));
		tab.setBorder(null);
		tab.setBackground(Color.WHITE);
		tab.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		tab.setBounds(0, 20, 453, 480);
		add(tab, BorderLayout.CENTER);
		
		tab.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				if(tab.getSelectedIndex() == 0){
					ViewPanel.setVisible(true);
					ViewTArea.setText("");
				}
				else if(tab.getSelectedIndex() == 1){
					ViewPanel.setVisible(true);
					ViewTArea.setText("");
				}
				else if(tab.getSelectedIndex() == 2){
					ViewPanel.setVisible(true);
					model2.clear();
					Search_txt.setText("");
					ViewTArea.setText("");
				}
				else if(tab.getSelectedIndex() == 3){
					ViewTArea.setText("");
					ViewPanel.setVisible(false);//패스워드변경 탭에서는 뷰가 사라짐
				}				
			}
		});
		      
		// Displaypanel

		DisplayPanel = new JPanel();
		DisplayPanel.setBackground(new Color(204, 255, 255));
		tab.addTab("Display", DisplayPanel);

		DisplayPanel.setPreferredSize(new Dimension(400, 300));
		DisplayPanel.setLayout(null);

		JLabel lblNewLabel = new JLabel("전화번호부");
		lblNewLabel.setFont(new Font("맑은 고딕", Font.BOLD, 16));
		lblNewLabel.setBounds(20, 23, 96, 33);
		DisplayPanel.add(lblNewLabel);

		ContactList = new JList(new DefaultListModel());
		ContactList.setForeground(new Color(51, 51, 51));
		ContactList.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		ContactList.setBounds(18, 65, 341, 380);
		model = (DefaultListModel) ContactList.getModel();
		DisplayPanel.add(ContactList);

		contact.loadCollection();

		model.clear();
		for (int i = 0; i < contact.getCount(); i++)
			model.addElement(contact.list(i));

		MouseListener mouseListener = new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 1) {
					int index = ContactList.locationToIndex(e.getPoint());
					contact.Store(index);
					ViewTArea.setText(contact.toString());
				}
			}
		};
		ContactList.addMouseListener(mouseListener);

		// Addpanel

		AddPanel = new JPanel();
		AddPanel.setBackground(new Color(204, 255, 255));
		tab.addTab("Add", AddPanel);

		AddPanel.setPreferredSize(new Dimension(400, 300));
		AddPanel.setLayout(null);

		AddButton = new JButton("추가");
		AddButton.setBackground(Color.WHITE);
		AddButton.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		AddButton.setBounds(291, 437, 72, 23);
		AddPanel.add(AddButton);

		AddButton.addActionListener(listener);

		Firstn_lbl = new JLabel("First name");
		Firstn_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		Firstn_lbl.setBounds(12, 48, 80, 15);
		AddPanel.add(Firstn_lbl);

		Lastn_lbl = new JLabel("Last name");
		Lastn_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		Lastn_lbl.setBounds(12, 82, 80, 15);
		AddPanel.add(Lastn_lbl);

		Firstn_txt = new JTextField();
		Firstn_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		Firstn_txt.setForeground(new Color(0, 102, 153));
		Firstn_txt.setBounds(133, 52, 116, 21);
		AddPanel.add(Firstn_txt);
		Firstn_txt.setColumns(10);

		Lastn_txt = new JTextField();
		Lastn_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		Lastn_txt.setForeground(new Color(0, 102, 153));
		Lastn_txt.setBounds(133, 86, 116, 21);
		AddPanel.add(Lastn_txt);
		Lastn_txt.setColumns(10);

		pos_lbl = new JLabel("Position");
		pos_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		pos_lbl.setBounds(12, 120, 57, 15);
		AddPanel.add(pos_lbl);

		pos_txt = new JTextField();
		pos_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		pos_txt.setForeground(new Color(0, 102, 153));
		pos_txt.setColumns(10);
		pos_txt.setBounds(133, 124, 116, 21);
		AddPanel.add(pos_txt);

		depart_lbl = new JLabel("Department");
		depart_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		depart_lbl.setBounds(12, 155, 80, 15);
		AddPanel.add(depart_lbl);

		depart_txt = new JTextField();
		depart_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		depart_txt.setForeground(new Color(0, 102, 153));
		depart_txt.setColumns(10);
		depart_txt.setBounds(133, 159, 116, 21);
		AddPanel.add(depart_txt);

		coname_lbl = new JLabel("Company name");
		coname_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		coname_lbl.setBounds(12, 191, 97, 15);
		AddPanel.add(coname_lbl);

		coname_txt = new JTextField();
		coname_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		coname_txt.setForeground(new Color(0, 102, 153));
		coname_txt.setColumns(10);
		coname_txt.setBounds(133, 195, 116, 21);
		AddPanel.add(coname_txt);

		address_lbl = new JLabel("Address");
		address_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		address_lbl.setBounds(12, 225, 80, 15);
		AddPanel.add(address_lbl);

		address_txt = new JTextField();
		address_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		address_txt.setForeground(new Color(0, 102, 153));
		address_txt.setColumns(10);
		address_txt.setBounds(133, 229, 234, 21);
		AddPanel.add(address_txt);

		telnum_lbl = new JLabel("Telephone number");
		telnum_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		telnum_lbl.setBounds(12, 258, 116, 15);
		AddPanel.add(telnum_lbl);

		telnum_txt = new JTextField();
		telnum_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		telnum_txt.setForeground(new Color(0, 102, 153));
		telnum_txt.setColumns(10);
		telnum_txt.setBounds(133, 262, 155, 21);
		AddPanel.add(telnum_txt);

		faxnum_lbl = new JLabel("Fax number");
		faxnum_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		faxnum_lbl.setBounds(12, 291, 80, 15);
		AddPanel.add(faxnum_lbl);

		faxnum_txt = new JTextField();
		faxnum_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		faxnum_txt.setForeground(new Color(0, 102, 153));
		faxnum_txt.setColumns(10);
		faxnum_txt.setBounds(133, 295, 116, 21);
		AddPanel.add(faxnum_txt);

		monum_lbl = new JLabel("Mobile number");
		monum_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		monum_lbl.setBounds(12, 325, 97, 15);
		AddPanel.add(monum_lbl);

		mobnum_txt = new JTextField();
		mobnum_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		mobnum_txt.setForeground(new Color(0, 102, 153));
		mobnum_txt.setColumns(10);
		mobnum_txt.setBounds(133, 329, 155, 21);
		AddPanel.add(mobnum_txt);

		email_lbl = new JLabel("Email address");
		email_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		email_lbl.setBounds(12, 363, 97, 15);
		AddPanel.add(email_lbl);

		email_txt = new JTextField();
		email_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		email_txt.setForeground(new Color(0, 102, 153));
		email_txt.setColumns(10);
		email_txt.setBounds(133, 367, 217, 21);
		AddPanel.add(email_txt);

		homp_lbl = new JLabel("Homepage");
		homp_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		homp_lbl.setBounds(12, 401, 97, 15);
		AddPanel.add(homp_lbl);

		homp_txt = new JTextField();
		homp_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		homp_txt.setForeground(new Color(0, 102, 153));
		homp_txt.setColumns(10);
		homp_txt.setBounds(133, 405, 217, 21);
		AddPanel.add(homp_txt);

		// SearchPanel

		SearchPanel = new JPanel();
		SearchPanel.setBackground(new Color(204, 255, 255));
		tab.addTab("Search", SearchPanel);

		SearchPanel.setPreferredSize(new Dimension(400, 300));
		SearchPanel.setLayout(null);

		SearchList = new JList(new DefaultListModel());
		SearchList.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		SearchList.setBounds(18, 169, 339, 255);
		SearchPanel.add(SearchList);

		Search_btn = new JButton("검색");
		Search_btn.setBackground(Color.WHITE);
		Search_btn.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		Search_btn.setBounds(252, 77, 75, 23);
		SearchPanel.add(Search_btn);

		Search_btn.addActionListener(listener);

		Search_txt = new JTextField();
		Search_txt.setForeground(new Color(0, 0, 51));
		Search_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		Search_txt.setBounds(52, 78, 188, 21);
		SearchPanel.add(Search_txt);
		Search_txt.setColumns(10);

		Search_lbl = new JLabel("검색결과");
		Search_lbl.setFont(new Font("맑은 고딕", Font.BOLD, 16));
		Search_lbl.setBounds(18, 131, 83, 28);
		SearchPanel.add(Search_lbl);

		search_lbl2 = new JLabel("이름으로 검색하세요.(한글/알파뱃)");
		search_lbl2.setFont(new Font("맑은 고딕", Font.BOLD, 13));
		search_lbl2.setBounds(52, 39, 242, 15);
		SearchPanel.add(search_lbl2);

		model2 = (DefaultListModel) SearchList.getModel();

		MouseListener mouseListener2 = new MouseAdapter() {//list관련 리스너
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 1) {
					int index = SearchList.locationToIndex(e.getPoint());
					contact.SearchStore(index);
					ViewTArea.setText(contact.toString());
				}
			}
		};
		SearchList.addMouseListener(mouseListener2);

		// PasswordPanel

		PasswordPanel = new JPanel();
		PasswordPanel.setBackground(new Color(204, 255, 255));
		tab.addTab("Password", PasswordPanel);

		PasswordPanel.setPreferredSize(new Dimension(600, 300));
		PasswordPanel.setLayout(null);

		pwbtn = new JButton("확인");
		pwbtn.setBackground(Color.WHITE);
		pwbtn.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		pwbtn.setBounds(280, 179, 62, 23);
		PasswordPanel.add(pwbtn);

		pwbtn.addActionListener(listener);

		password = new JLabel("Password : ");
		password.setFont(new Font("맑은 고딕", Font.PLAIN, 14));
		password.setBounds(26, 183, 81, 15);
		PasswordPanel.add(password);

		pwlbl = new JLabel("새로운 비밀번호를 입력하세요.");
		pwlbl.setFont(new Font("맑은 고딕", Font.BOLD, 14));
		pwlbl.setBounds(77, 126, 222, 23);
		PasswordPanel.add(pwlbl);

		passwordField = new JTextField();
		passwordField.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		passwordField.setForeground(new Color(0, 0, 51));
		passwordField.setBounds(110, 180, 158, 21);
		PasswordPanel.add(passwordField);
		passwordField.setColumns(10);
		
		//수정창
		ModifyPanel = new JPanel();
		ModifyPanel.setLayout(null);
		ModifyPanel.setBackground(new Color(204, 255, 255));
		ModifyPanel.setPreferredSize(new Dimension(463, 500));

		M_button = new JButton("확인");
		M_button.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_button.setBackground(Color.WHITE);
		M_button.setBounds(354, 456, 97, 23);
		ModifyPanel.add(M_button);
		M_button.addActionListener(listener);

		M_Firstn_lbl = new JLabel("First name");
		M_Firstn_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_Firstn_lbl.setBounds(34, 70, 80, 15);
		ModifyPanel.add(M_Firstn_lbl);

		M_Lastn_lbl = new JLabel("Last name");
		M_Lastn_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_Lastn_lbl.setBounds(34, 104, 80, 15);
		ModifyPanel.add(M_Lastn_lbl);

		M_Firstn_txt = new JTextField();
		M_Firstn_txt.setForeground(new Color(0, 0, 51));
		M_Firstn_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_Firstn_txt.setColumns(10);
		M_Firstn_txt.setBounds(173, 70, 234, 21);
		ModifyPanel.add(M_Firstn_txt);

		M_Lastn_txt = new JTextField();
		M_Lastn_txt.setForeground(new Color(0, 0, 51));
		M_Lastn_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_Lastn_txt.setColumns(10);
		M_Lastn_txt.setBounds(173, 104, 234, 21);
		ModifyPanel.add(M_Lastn_txt);

		M_pos_lbl = new JLabel("Position");
		M_pos_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_pos_lbl.setBounds(34, 142, 57, 15);
		ModifyPanel.add(M_pos_lbl);

		M_pos_txt = new JTextField();
		M_pos_txt.setForeground(new Color(0, 0, 51));
		M_pos_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_pos_txt.setColumns(10);
		M_pos_txt.setBounds(173, 142, 234, 21);
		ModifyPanel.add(M_pos_txt);

		M_depart_lbl = new JLabel("Department");
		M_depart_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_depart_lbl.setBounds(34, 177, 80, 15);
		ModifyPanel.add(M_depart_lbl);

		M_depart_txt = new JTextField();
		M_depart_txt.setForeground(new Color(0, 0, 51));
		M_depart_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_depart_txt.setColumns(10);
		M_depart_txt.setBounds(173, 177, 234, 21);
		ModifyPanel.add(M_depart_txt);

		M_coname_lbl = new JLabel("Company name");
		M_coname_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_coname_lbl.setBounds(34, 213, 97, 15);
		ModifyPanel.add(M_coname_lbl);

		M_coname_txt = new JTextField();
		M_coname_txt.setForeground(new Color(0, 0, 51));
		M_coname_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_coname_txt.setColumns(10);
		M_coname_txt.setBounds(173, 213, 234, 21);
		ModifyPanel.add(M_coname_txt);

		M_address_lbl = new JLabel("Address");
		M_address_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_address_lbl.setBounds(34, 247, 80, 15);
		ModifyPanel.add(M_address_lbl);

		M_address_txt = new JTextField();
		M_address_txt.setForeground(new Color(0, 0, 51));
		M_address_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_address_txt.setColumns(10);
		M_address_txt.setBounds(173, 247, 234, 21);
		ModifyPanel.add(M_address_txt);

		M_telnum_lbl = new JLabel("Telephone number");
		M_telnum_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_telnum_lbl.setBounds(34, 280, 116, 15);
		ModifyPanel.add(M_telnum_lbl);

		M_telnum_txt = new JTextField();
		M_telnum_txt.setForeground(new Color(0, 0, 51));
		M_telnum_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_telnum_txt.setColumns(10);
		M_telnum_txt.setBounds(173, 280, 234, 21);
		ModifyPanel.add(M_telnum_txt);

		M_faxnum_lbl = new JLabel("Fax number");
		M_faxnum_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_faxnum_lbl.setBounds(34, 313, 80, 15);
		ModifyPanel.add(M_faxnum_lbl);

		M_faxnum_txt = new JTextField();
		M_faxnum_txt.setForeground(new Color(0, 0, 51));
		M_faxnum_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_faxnum_txt.setColumns(10);
		M_faxnum_txt.setBounds(173, 313, 234, 21);
		ModifyPanel.add(M_faxnum_txt);

		M_monum_lbl = new JLabel("Mobile number");
		M_monum_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_monum_lbl.setBounds(34, 347, 97, 15);
		ModifyPanel.add(M_monum_lbl);

		M_mobnum_txt = new JTextField();
		M_mobnum_txt.setForeground(new Color(0, 0, 51));
		M_mobnum_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_mobnum_txt.setColumns(10);
		M_mobnum_txt.setBounds(173, 347, 234, 21);
		ModifyPanel.add(M_mobnum_txt);

		M_email_lbl = new JLabel("Email address");
		M_email_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_email_lbl.setBounds(34, 385, 97, 15);
		ModifyPanel.add(M_email_lbl);

		M_email_txt = new JTextField();
		M_email_txt.setForeground(new Color(0, 0, 51));
		M_email_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_email_txt.setColumns(10);
		M_email_txt.setBounds(173, 385, 234, 21);
		ModifyPanel.add(M_email_txt);

		M_homp_lbl = new JLabel("Homepage");
		M_homp_lbl.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_homp_lbl.setBounds(34, 423, 97, 15);
		ModifyPanel.add(M_homp_lbl);

		M_homp_txt = new JTextField();
		M_homp_txt.setForeground(new Color(0, 0, 51));
		M_homp_txt.setFont(new Font("맑은 고딕", Font.PLAIN, 13));
		M_homp_txt.setColumns(10);
		M_homp_txt.setBounds(173, 423, 234, 21);
		ModifyPanel.add(M_homp_txt);

		M_main_lbl = new JLabel("수정할 내용을 입력하세요.");
		M_main_lbl.setFont(new Font("맑은 고딕", Font.BOLD, 16));
		M_main_lbl.setBounds(34, 22, 210, 30);
		ModifyPanel.add(M_main_lbl);
	}

	

	private class ButtonListener implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			if (event.getSource() == AddButton) // 연락처 등록 버튼
			{
				if (Firstn_txt.getText().equals("") || Lastn_txt.getText().equals("") || pos_txt.getText().equals("")
						|| depart_txt.getText().equals("") || coname_txt.getText().equals("") || address_txt.getText().equals("")
						|| telnum_txt.getText().equals("") || faxnum_txt.getText().equals("") || mobnum_txt.getText().equals("")
						|| email_txt.getText().equals("") || homp_txt.getText().equals("")) 
				{
					JOptionPane.showMessageDialog(null, "모든 정보를 입력해주세요.");
				} 
				else if (contact.findContact(Firstn_txt.getText(), Lastn_txt.getText()) < contact.getCount()) {
					JOptionPane.showMessageDialog(null, "같은이름이 존재합니다.");
				}
				else{
					int config=1;
					Boolean fi = true;
					Boolean la = true;
					Boolean po = true;
					Boolean de = true;
					Boolean te = true;
					Boolean fa = true;
					
					char[] str= new char[50];					
					str = Firstn_txt.getText().toCharArray();
					for(int k=0;k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "이름을 다시 입력해주세요.");
							config=0;
							fi = false;
							break;
						}					
					if(fi){
					str = Lastn_txt.getText().toCharArray();
					for(int k=0;k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "성을 다시 입력해주세요.");
							config=0;
							la = false;
							break;
						}
					}					
					if(fi && la){
					str = pos_txt.getText().toCharArray();
					for(int k=0;k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "직위를 다시 입력해주세요.");
							config=0;
							po = false;
							break;
						}
					}					
					if(fi && la && po){
					str = depart_txt.getText().toCharArray();
					for(int k = 0; k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "부서를 다시 입력해주세요.");
							config = 0;
							de = false;
							break;
						}
					}
					if(fi && la && po && de){
					str = telnum_txt.getText().toCharArray();
					for(int k = 0; k<str.length;k++)
						if(!('0'<=str[k] && '9'>=str[k] || '-'==str[k])){
							JOptionPane.showMessageDialog(null, "전화번호를 다시 입력해주세요.");
							config = 0;
							te = false;
							break;
						}
					}
					if(fi && la && po && de && te){
					str = faxnum_txt.getText().toCharArray();	
					for(int k = 0; k<str.length;k++)
						if(!('0'<=str[k] && '9'>=str[k]||'-'==str[k])){
							JOptionPane.showMessageDialog(null, "팩스번호를 다시 입력해주세요.");
							config = 0;
							fa = false;
							break;
						}
					}
					if(fi && la && po && de && te && fa){
					str = mobnum_txt.getText().toCharArray();
					for(int k = 0; k<str.length;k++)
						if(!('0'<=str[k] && '9'>=str[k]|| '-'==str[k])){
							JOptionPane.showMessageDialog(null, "휴대폰번호를 다시 입력해주세요.");
							config = 0;
							break;
						}
					}					
					if(config == 1){
						
						contact.addContact(Firstn_txt.getText(), Lastn_txt.getText(), pos_txt.getText(), depart_txt.getText(), coname_txt.getText(),
								address_txt.getText(), telnum_txt.getText(), faxnum_txt.getText(), mobnum_txt.getText(), email_txt.getText(), homp_txt.getText());
						ViewTArea.setText(contact.toString());
						model.clear();
						for (int i = 0; i < contact.getCount(); i++)
							model.addElement(contact.list(i));
						Firstn_txt.setText("");
						Lastn_txt.setText("");
						pos_txt.setText("");
						depart_txt.setText("");
						coname_txt.setText("");
						address_txt.setText("");
						telnum_txt.setText("");
						faxnum_txt.setText("");
						mobnum_txt.setText("");
						email_txt.setText("");
						homp_txt.setText("");// 텍스트 필드 초기화					
					}
				}
			}

			if (event.getSource() == modifyButton) // 연락처 수정 버튼
			{
				String str = contact.searchFname();
				if (str.equals("")) {
					JOptionPane.showMessageDialog(null, "수정 할 연락처 정보를 view에 띄워주세요.");
				} 
				else {
					modiframe = new JFrame("수정");
					modiframe.getContentPane().add(ModifyPanel);
					modiframe.pack();
					modiframe.setVisible(true);

					M_Firstn_txt.setText(contact.searchFname());
					M_Lastn_txt.setText(contact.searchLname());
					M_pos_txt.setText(contact.searchPos());
					M_depart_txt.setText(contact.searchDept());
					M_coname_txt.setText(contact.searchComp());
					M_address_txt.setText(contact.searchAddr());
					M_telnum_txt.setText(contact.searchTel());
					M_faxnum_txt.setText(contact.searchFax());
					M_mobnum_txt.setText(contact.searchMobile());
					M_email_txt.setText(contact.searchEmail());
					M_homp_txt.setText(contact.searchHomepg());
				}
			}
			if(event.getSource() == M_button){//수정확인 버튼
				if(M_Firstn_txt.getText().equals("")||M_Lastn_txt.getText().equals("")||M_pos_txt.getText().equals("")||
						M_depart_txt.getText().equals("")||M_coname_txt.getText().equals("")||M_address_txt.getText().equals("")||
						M_telnum_txt.getText().equals("")|| M_faxnum_txt.getText().equals("")|| M_mobnum_txt.getText().equals("")||
						M_email_txt.getText().equals("")||M_homp_txt.getText().equals("")){	
					JOptionPane.showMessageDialog(null, "모든 정보를 입력해주세요.");	
				}
				else{
					int config=1;
					Boolean fi = true;
					Boolean la = true;
					Boolean po = true;
					Boolean de = true;
					Boolean te = true;
					Boolean fa = true;
					
					char[] str= new char[50];					
					str = M_Firstn_txt.getText().toCharArray();
					for(int k=0;k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "이름을 다시 입력해주세요.");
							config=0;
							fi = false;
							break;
						}					
					if(fi){
					str = M_Lastn_txt.getText().toCharArray();
					for(int k=0;k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "성을 다시 입력해주세요.");
							config=0;
							la = false;
							break;
						}
					}					
					if(fi && la){
					str = M_pos_txt.getText().toCharArray();
					for(int k=0;k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "직위를 다시 입력해주세요.");
							config=0;
							po = false;
							break;
						}
					}					
					if(fi && la && po){
					str = M_depart_txt.getText().toCharArray();
					for(int k = 0; k<str.length;k++)
						if(!(('A'<=str[k]&&str[k]<='Z')||('a'<=str[k]&&str[k]<='z')||('가'<=str[k]&&str[k]<='힣'))){
							JOptionPane.showMessageDialog(null, "부서를 다시 입력해주세요.");
							config = 0;
							de = false;
							break;
						}
					}
					if(fi && la && po && de){
					str = M_telnum_txt.getText().toCharArray();
					for(int k = 0; k<str.length;k++)
						if(!('0'<=str[k] && '9'>=str[k] || '-'==str[k])){
							JOptionPane.showMessageDialog(null, "전화번호를 다시 입력해주세요.");
							config = 0;
							te = false;
							break;
						}
					}
					if(fi && la && po && de && te){
					str = M_faxnum_txt.getText().toCharArray();	
					for(int k = 0; k<str.length;k++)
						if(!('0'<=str[k] && '9'>=str[k]||'-'==str[k])){
							JOptionPane.showMessageDialog(null, "팩스번호를 다시 입력해주세요.");
							config = 0;
							fa = false;
							break;
						}
					}
					if(fi && la && po && de && te && fa){
					str = M_mobnum_txt.getText().toCharArray();
					for(int k = 0; k<str.length;k++)
						if(!('0'<=str[k] && '9'>=str[k]|| '-'==str[k])){
							JOptionPane.showMessageDialog(null, "휴대폰번호를 다시 입력해주세요.");
							config = 0;
							break;
						}
					}					
					if(config==1){	
					contact.modifyContact(M_Firstn_txt.getText(), M_Lastn_txt.getText(), M_pos_txt.getText(), 
							M_depart_txt.getText(), M_coname_txt.getText(), M_address_txt.getText(), M_telnum_txt.getText(), 
							M_faxnum_txt.getText(), M_mobnum_txt.getText(), M_email_txt.getText(), M_homp_txt.getText());
				    modiframe.dispose();
				    ViewTArea.setText(contact.toString());
					model.clear();
					for (int i = 0; i < contact.getCount(); i++)
						model.addElement(contact.list(i));
					model2.clear();
					contact.search(Search_txt.getText());
					for (int i = 0; i < contact.getCount2(); i++)
						model2.addElement(contact.Searchlist(i));					
					}
				}
			}
			if (event.getSource() == deleteButton) // 연락처 삭제 버튼
			{
				contact.deleteContact();
				ViewTArea.setText("");
				model.clear();
				for (int i = 0; i < contact.getCount(); i++)
					model.addElement(contact.list(i));

				if (!contact.Getname().equals(""))
					JOptionPane.showMessageDialog(null, contact.Getname() + "의 정보를 삭제하였습니다.");
			}		
			if (event.getSource() == Search_btn) // 연락처 검색 버튼
			{
				if (Search_txt.getText().equals("")){
					JOptionPane.showMessageDialog(null, "검색할 이름을 입력해주세요");
					model2.clear();
				}
				else {
					contact.search(Search_txt.getText());
					char[] str = new char[50];
					str = Search_txt.getText().toCharArray();
					for (int k = 0; k < str.length; k++)
						if (!(('A' <= str[k] && str[k] <= 'Z') || ('a' <= str[k] && str[k] <= 'z') || ('가' <= str[k] && str[k] <= '힣'))) {
							JOptionPane.showMessageDialog(null, "검색어를 다시 입력해주세요.");
							break;
						}
					model2.clear();
					for (int i = 0; i < contact.getCount2(); i++)
						model2.addElement(contact.Searchlist(i));
					if (model2.getSize() == 0)
						JOptionPane.showMessageDialog(null, "검색결과가 없습니다.");
				}
			}
			if (event.getSource() == savebtn)//contact 정보를 파일에 저장하는 저장버튼
				contact.savedata();
			if (event.getSource() == pwbtn) {//비밀번호 정보를 저장하는 버튼
				contact.SetPW2(passwordField.getText());
				passwordField.setText("");
			    contact.savePW();
			}
		}
	}
}
